//
//  DigitalTransferRequestViewController.m
//  HYApp
//
//  Created by Jianbo Cai on 2020/8/13.
//  Copyright © 2020 Unidax. All rights reserved.
//

#import "DigitalTransferRequestViewController.h"
#import "HYNetHelper.h"
#import "HistoryMainViewController.h"
@implementation DigitalTransferRequestEntity
@end


@interface DigitalTransferRequestViewController ()

@property (weak, nonatomic) IBOutlet UILabel *fromAccountVaule;
@property (weak, nonatomic) IBOutlet UILabel *toAccountVaule;
@property (weak, nonatomic) IBOutlet UILabel *amountVaule;
@property (weak, nonatomic) IBOutlet UILabel *tenorVaule;
@property (weak, nonatomic) IBOutlet UILabel *transferFeeVaule;

@property (weak, nonatomic) IBOutlet UILabel *fromAccountTitle;
@property (weak, nonatomic) IBOutlet UILabel *toAccountTitle;
@property (weak, nonatomic) IBOutlet UILabel *amountTitle;
@property (weak, nonatomic) IBOutlet UILabel *tenorTitle;
@property (weak, nonatomic) IBOutlet UILabel *transferFeeTitle;

@property (weak, nonatomic) IBOutlet UIButton *comfirmButton;
@end

@implementation DigitalTransferRequestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = JFMainLocalizedString(@"withdraw.confirm-transfer");
    
    self.fromAccountVaule.text = self.entity.fromAccount;
    self.toAccountVaule.text = self.entity.toAccount;
    self.amountVaule.text = self.entity.amount;
    self.tenorVaule.text = self.entity.tenor.des;
    self.transferFeeVaule.text = self.entity.tenor.fee;
    
    self.fromAccountTitle.text = [JFMainLocalizedString(@"transactions.from_wallet") stringByAppendingString:@":"];
    self.toAccountTitle.text = [JFMainLocalizedString(@"transactions.to_wallet") stringByAppendingString:@":"];
    self.amountTitle.text = [JFMainLocalizedString(@"deal.amount") stringByAppendingString:@":"];
    self.tenorTitle.text = [JFMainLocalizedString(@"Tenor") stringByAppendingString:@":"];
    self.transferFeeTitle.text = [JFMainLocalizedString(@"Transfer Fee") stringByAppendingString:@":"];
    
    [self.comfirmButton setTitle:JFMainLocalizedString(@"confirm") forState:UIControlStateNormal];
}

- (void)pushHistoryVC {
    HistoryMainViewController *vc = [[HistoryMainViewController alloc]init];
    vc.selectIndex = 3;
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)confirm:(id)sender {
    WEAKSELF
    [HYNetHelper send:self.entity.asset_symbol amount:self.entity.amount wallet_id:self.entity.wallet_id to_wallet_id:self.entity.to_wallet_id to:nil tenor:self.entity.tenor.name verifyType:nil token:nil callBack:^(JFResultVo *resultVo) {
        if (!resultVo.errorNo)  {
            NSString *string = [NSString stringWithFormat:@"You have requested to transfer %@ %@ successfully", self.entity.amount, weakSelf.entity.asset_symbol];
            NSRange range = [string rangeOfString:self.entity.amount];
            NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:string];
            [attStr addAttributes:@{NSForegroundColorAttributeName: UIColorFromHex(0xF8A828)} range:NSMakeRange(range.location, self.entity.amount.length + 4)];

            FZAlertController *alertController = [FZAlertController alertControllerWithTitleImage:[UIImage imageNamed:@"alert_icon1"] title:@"Transfer Requested" customView:nil message:string];
            alertController.messageAttStr = attStr;
            alertController.showCloseBtn = YES;
            alertController.messageAlignment = NSTextAlignmentCenter;

            FZAlertAction *action = [FZAlertAction actionWithTitle:JFMainLocalizedString(@"deposit.see-details") style:UIAlertActionStyleDefault handler:^(FZAlertAction *action) {
                [weakSelf pushHistoryVC];
                                }];
            [alertController addAction:action];
            [self presentViewController:alertController animated:YES completion:nil];
        }else {
            FZAlertController *alertController = [FZAlertController alertControllerWithTitleImage:[UIImage imageNamed:@"alert_icon_failed"] title:@"Requested failed" customView:nil message:nil];
            alertController.showCloseBtn = YES;
            alertController.messageAlignment = NSTextAlignmentCenter;

            FZAlertAction *action = [FZAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(FZAlertAction *action) {
                                }];
            [alertController addAction:action];
            [self presentViewController:alertController animated:YES completion:nil];
        }
    }];
}

@end
